import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:oktoast/oktoast.dart';
import 'package:xinxuan/controllers/common_page_controller.dart';
import 'package:xinxuan/middleware/router_auth.dart';
import 'package:xinxuan/router/app_pages.dart';
import 'package:xinxuan/utils/color_util.dart';

class MyApp extends StatelessWidget {

  final CommonPageController commonPageController = Get.put(CommonPageController());

  @override
  Widget build(BuildContext context) {
    if (Theme.of(context).platform == TargetPlatform.android) {
      SystemUiOverlayStyle _style = SystemUiOverlayStyle(statusBarColor: Colors.transparent);
      SystemChrome.setSystemUIOverlayStyle(_style);
    }
    SystemChrome.setPreferredOrientations([
      DeviceOrientation.portraitUp, //只能纵向
      DeviceOrientation.portraitDown,//只能纵向
    ]);
    return ScreenUtilInit(
      designSize: Size(375, 812),
      splitScreenMode: true, 
      builder: () => OKToast(
        dismissOtherOnShow: true,
        radius: 5,
        backgroundColor: bgBlackColor_50,
        position: ToastPosition.bottom,
        textPadding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
        textStyle: TextStyle(
          color: textWhiteColor,
          fontSize: 14.sp
        ),
        child: GetMaterialApp(
          debugShowCheckedModeBanner: false,
          // showPerformanceOverlay: true,
          initialBinding: BindingsBuilder(() {
            Get.put(RouteAuthMiddleware());
          }),
          initialRoute: AppPages.START_PAGE,
          getPages: AppPages.routers,
          title: '魔法星选',
          theme: ThemeData(
            primaryColor: bgWhiteColor,
            scaffoldBackgroundColor: bgWhiteColor,
            appBarTheme: AppBarTheme(
              backgroundColor: bgWhiteColor
            )
          ),
          builder: EasyLoading.init(),
          localizationsDelegates: [
            GlobalMaterialLocalizations.delegate,
            GlobalWidgetsLocalizations.delegate,
            GlobalCupertinoLocalizations.delegate,
          ],
          supportedLocales: [
            const Locale('zh', 'CN'),
            const Locale('en', 'US'),
          ]
        )
      ),
    );
  }
}